#include "mainwindow.h"
#include <QLabel>
#include <QSpinBox>
#include "ui_mainwindow.h"
#include <QToolButton>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 菜单
    QMenu* editMenu = ui->menuBar->addMenu("编辑(&E)");

    // 添加子财产
    QAction* copyAction = editMenu->addAction("内容(&C)");
    // 设置快捷键
    copyAction->setShortcut(QKeySequence("Ctrl + C"));
    // 添加到工具栏
    ui->mainToolBar->addAction(copyAction);
    // 设置动作分组
    QActionGroup* group = new QActionGroup(this);
    QAction* action_L = group->addAction("左对齐(&L)");
    QAction* action_R = group->addAction("右对齐(&R)");
    QAction* action_C = group->addAction("两端对齐(&C)");

    action_L->setCheckable(true);
    action_R->setCheckable(true);
    action_C->setCheckable(true);

    editMenu->addSeparator();   // 添加分割线
    editMenu->addAction(action_L);
    editMenu->addAction(action_R);
    editMenu->addAction(action_C);


    // 工具栏 添加部件
    QToolButton* toolBtn = new QToolButton(this);
    toolBtn->setText("颜色");
    QMenu* colorMenu = new QMenu(this);
    colorMenu->addAction("红色");
    colorMenu->addAction("绿色");
    toolBtn->setMenu(colorMenu);
    // 弹出菜单
    toolBtn->setPopupMode(QToolButton::MenuButtonPopup);
    ui->mainToolBar->addWidget(toolBtn);

    QSpinBox* spbox = new QSpinBox(this);
    ui->mainToolBar->addWidget(spbox);


    // 设置提示信息 临时信息
    ui->statusBar->showMessage(QString("欢迎。。。"),3000);

    QLabel* tag = new QLabel("wwwww");
    // 添加永久性部件
    ui->statusBar->addPermanentWidget(tag);
}

MainWindow::~MainWindow()
{
    delete ui;
}
